package br.com.ufpr.sgp.util.session;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.wicket.request.Request;
import org.apache.wicket.session.HttpSessionStore;

/**
 * Session store customizada, implementada para conter método {@link CustomSessionStore#setMaxInactiveInterval(Request, int)}.
 * 
 * @author Willian Tanaka
 */
public class CustomSessionStore extends HttpSessionStore {

    private static final Logger log = Logger.getLogger(CustomSessionStore.class);

    /**
     * Seta o tempo máximo de inatividade.
     * 
     * @param request
     * @param mins
     */
    public void setMaxInactiveInterval(final Request request, final int mins) {
        log.debug("Setando timeout da sessão: " + mins + " minutos...");
        final HttpServletRequest servletReq = (HttpServletRequest) request.getContainerRequest();
        final HttpSession session = servletReq.getSession();
        if (session != null) {
            session.setMaxInactiveInterval(mins * 60);
        }
    }

}
